package cotroller;

import com.google.gson.Gson;
import vo.Good;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "GoodServlet",value = "/goodServlet")
public class GoodServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("gbk");
        response.setCharacterEncoding("gbk");
        response.setContentType("text/html;charset=gbk");

        List<Good> goodList=new ArrayList<>();
        goodList.add(new Good(1,"aaa",21f,"images/product/1.jpg",100,"非常牛逼"));
        goodList.add(new Good(2,"aaa",21f,"",100,""));
        goodList.add(new Good(3,"aaa",21f,"",100,""));
        goodList.add(new Good(4,"aaa",21f,"",100,""));
        goodList.add(new Good(5,"aaa",21f,"",100,""));

        HttpSession se=request.getSession();
        se.setAttribute("allgood",goodList);
//        Gson gson=new Gson();
//        String s=gson.toJson(goodList);
//        PrintWriter writer=response.getWriter();
//        writer.println(s);
        request.getRequestDispatcher("listgood.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
